import {DirectiveBinding} from 'vue'


const observer = new ResizeObserver((entries) => {
    entries.forEach(item => {
        const target = item.target as any;
        let binding: DirectiveBinding;
        if (!!(binding = target.binding)) {
            if (typeof binding.value === 'function') {
                binding.value(item.target);
            } else {
                const arg = binding.arg;
                switch (arg) {

                }
            }
        } else {
            console.warn('请输入指令参数')
        }
    })
})


export const resize = {
    activated: (el: any, binding: any) => {
        el.binding = binding;
        observer.observe(el);
    },
    mounted(el: any, binding: DirectiveBinding) {
        el.binding = binding;
        observer.observe(el);
    },
    unmounted(el: any) {
        delete el.binding;
        observer.unobserve(el)
    },
    deactivated: (el: any) => {
        delete el.binding;
        observer.unobserve(el)
    }
}
